package com.java.ttt.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;

public class MoveDao {

	public int saveMove(String userName, int gameID, String move) {

		int i = 0;
		
		String sql = "insert into ttt3.GameState values (?,?,?,?)";

		try {
			Connection conn = BaseDbConnection.getConnection();

			PreparedStatement ps = conn.prepareStatement(sql);
			java.util.Date date = new Date();
			Timestamp timestamp = new Timestamp(date.getTime());
			ps.setInt(1, gameID);
			ps.setString(2, userName);
			ps.setString(3, move);
			ps.setTimestamp(4, timestamp);
			i = ps.executeUpdate();

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}

		return i;
	}
}
